<template>
    <div class="content">
        <el-row>
            <el-col :span="24">
                <el-button type="primary" :icon="CirclePlus" @click="onEdit(0)">添加</el-button>
            </el-col>
        </el-row>
        
        <el-table :data="tableData" border v-loading="form.loading" style="width: 100%;font-size: 16px;">
            <el-table-column type="index" align="center" :index="indexMethod" label="序号" width="60" />
            <el-table-column prop="b_name" align="center" label="购买方名称"  />
            <el-table-column prop="b_mobile" align="center" label="购买方联系电话" />
            <el-table-column prop="price" align="center" label="开票金额" />
            <el-table-column prop="b_bank_account" align="center" label="销售方银行账号" />
            <el-table-column prop="tax_rate" align="center" label="税率" width="80" />
            <el-table-column label="申请状态" align="center" width="100">
                <template #default="scope">
                    <el-text type="primary" v-if="scope.row.application" @click="onApplyRecord(scope.row)" class="cp">{{scope.row.application.status_text}}</el-text>
                </template>
            </el-table-column>
            <el-table-column fixed="right" label="操作" width="120" align="center">
                <template #default="scope">
                    <el-link type="primary" @click="onEdit(scope.row.id)" >编辑</el-link>
                    <el-popconfirm title="确定要删除么?" @confirm="onDelete(scope.row.id)">
                        <template #reference>
                            <el-link type="danger" >删除</el-link>
                        </template>
                    </el-popconfirm>
                </template>
            </el-table-column>
        </el-table>
    </div>

    <el-dialog v-model="isApplyRecord" title="申请进度" width="50%">
        <component :is="applyRecord" :id = editId />
    </el-dialog>
</template>

<script lang="ts" setup>
import { ref,onMounted } from 'vue'
import { CirclePlus} from '@element-plus/icons-vue'
import http from '../../../../util/request';
import router from '../../../../router';
import applyRecord from "@/components/applyRecord.vue";
import { ElMessage } from 'element-plus';

const indexMethod = (index: number) => {
  return index+= 1
}
const editId = ref(0)
const isApplyRecord = ref(false)
const form = ref<any>({search:'',page:0,type_id:0,current:0,total:10,limit:20,loading:false,parentBorder:false})

const tableData = ref<any>([])

const onGetData = () => {
    form.value.loading = true
    http.post('/projectInvoice',form.value).then((response:any)=>{
        form.value.loading = false
        tableData.value = response.data.data
    })
}

const onDelete = (id: number) => {
    http.delete('/projectInvoice/'+id).then((response:any)=>{
        if(response.data.code != 200){
            ElMessage.error(response.data.msg);return;
        }
        ElMessage.success(response.data.msg);
        onGetData();
    })
}

const onEdit = (id: number) => {
    router.push({ name: 'projectInvoiceEdit',params: { id: id }})
}

const onApplyRecord = (data: any) => {
    editId.value = data.application.id
    isApplyRecord.value = true
}

onMounted(()=>{
    onGetData()
})

</script>

<style scoped>

</style>